fix: removeCells on parent node leaves orphan children causing duplicates#5039
Open
fix: removeCells on parent node leaves orphan children causing duplicates#5039
Conversation
Co-authored-by: hustcc <7856674+hustcc@users.noreply.github.com>
Copilot
AI
changed the title
[WIP] Fix issue with removeCells method leading to duplicate nodes
fix: removeCells on parent node leaves orphan children causing duplicates
Feb 25, 2026
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## master #5039 +/- ##
==========================================
+ Coverage 83.38% 83.39% +0.01%
==========================================
Files 332 332
Lines 38487 38498 +11
Branches 7898 7905 +7
==========================================
+ Hits 32093 32107 +14
+ Misses 6371 6368 -3
Partials 23 23
Flags with carried forward coverage won't be shown. Click here to find out more.
🚀 New features to boost your workflow:
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
When removing a parent node via
removeCells, its children are not recursively removed from the model, leaving orphan nodes. Subsequent re-creation of nodes with the same IDs results in apparent duplicates.Root Cause
collection.removeCellssetscell.model = null(via theremovedevent →onCellRemoved) before callingcell.remove(). Insideremove(),eachChild()callsgetChildren()which requiresthis.modelto resolve child IDs — returningnullwhen model is already null. Children are silently skipped.Changes
src/model/cell.ts—remove(): Fall back to_childrencache whengetChildren()returnsnulldue to model being null, ensuring children are still recursively removed:src/model/cell.ts—remove(): Keepparent._childrenin sync when directly mutatingparent.store(bypassingsetChildren()), so the fallback cache is not stale.__tests__/model/cell.spec.ts: Add test that simulates the actualcollection.removeCellsflow (model set tonullbeforeremove()is called) and asserts children are removed from the model.Original prompt
✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.